home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / execbep.com / EXECBEEP.VS2 < prev    next >
Encoding:
Text File  |  1988-02-27  |  4.3 KB  |  173 lines

  1. name execbeep
  2.  
  3. dp        equ    dword ptr
  4. of        equ    offset
  5.  
  6. code        segment
  7.         assume    cs:code, ds:code
  8.         org    100h
  9.  
  10. begin:        jmp    start
  11.  
  12. beep        proc            ; beep the speaker
  13.         push    ax        ; save
  14.         push    cx
  15.         in    al,97        ; get port values
  16.         and    al,0feh        ; turn speaker on
  17.         out    97,al
  18.         mov    cx,bx        ; cycles to cx
  19. more_sound:    push    cx        ; save cycles
  20.         xor    al,2        ; flip push/pull
  21.         out    97,al
  22.         mov    cx,dx        ; wait
  23. part1:        loop    part1
  24.         xor    al,2        ; flip push/pull
  25.         out    97,al
  26.         mov    cx,dx        ; wait
  27. part2:        loop    part2
  28.         pop    cx
  29.         loop    more_sound
  30.         pop    cx        ; restore
  31.         pop    ax
  32.         ret
  33. beep        endp
  34.  
  35. beep_low    proc
  36.         push    bx
  37.         push    dx
  38.         mov    bx,50        ; number of cycles
  39.         mov    dx,100        ; half cycle time
  40.         call    beep
  41.         pop    dx
  42.         pop    bx
  43.         ret
  44. beep_low    endp
  45.  
  46. beep_high    proc
  47.         push    bx
  48.         push    dx
  49.         mov    bx,100        ; number of cycles
  50.         mov    dx,50        ; half cycle time
  51.         call    beep
  52.         pop    dx
  53.         pop    bx
  54.         ret
  55. beep_high    endp
  56.  
  57. ; +++ EDR 2/27/88
  58.  
  59. space           db      ' ',0       ; just a space
  60. cr_lf           db      13,10,0     ; carriage return/line feed
  61.  
  62. tty_str         proc                ; show string in ES:SI, max of CX chars
  63.  
  64.                 jmp     short load  ; make sure string isn't null
  65.  
  66.         write:  mov     ah,0EH      ; write TTY service (char in AL)
  67.                 int     10H         ; kick BIOS
  68.  
  69.                 inc     si          ; point to next char
  70.                 dec     cx          ; and decrement count
  71.  
  72.         load:   mov     al,es:[si]  ; load char to show
  73.                 or      al,al       ; is it end of asciiz string?
  74.                 jz      done        ; yes
  75.                 cmp     cx,0        ; did we reach max char count?
  76.                 jnz     write       ; no- write it
  77.  
  78.         done:   ret
  79.  
  80. tty_str         endp
  81.  
  82. show_cmd        proc                    ; show the exec command line
  83.  
  84.                 push    ax              ; save the world
  85.                 push    cx
  86.                 push    dx
  87.                 push    si
  88.                 push    di
  89.                 push    es
  90.                 push    bx
  91.  
  92.                 mov     ax,ds           ; show command name from ds:dx
  93.                 mov     es,ax
  94.                 mov     si,dx
  95.                 mov     cx,64
  96.                 call    tty_str
  97.                 mov     ax,cs           ; followed by a space (just in case)
  98.                 mov     es,ax
  99.                 mov     si,offset space
  100.                 mov     cx,64
  101.                 call    tty_str
  102.  
  103.                 pop     bx              ; get original es:bx back
  104.                 pop     es
  105.                 push    es
  106.                 push    bx
  107.  
  108.                 mov     si,es:[bx+2]    ; set es:si to command arguments
  109.                 mov     ax,es:[bx+4]
  110.                 mov     es,ax
  111.  
  112.                 mov     cl,es:[si]      ; get char count in cx
  113.                 xor     ch,ch
  114.                 inc     si              ; skip to actual command chars
  115.                 call    tty_str         ; and show 'em
  116.  
  117.                 mov     ax,cs           ; skip up a line
  118.                 mov     es,ax
  119.                 mov     si,offset cr_lf
  120.                 mov     cx,64
  121.                 call    tty_str
  122.  
  123.                 pop     bx              ; restore the world
  124.                 pop     es
  125.                 pop     di
  126.                 pop     si
  127.                 pop     dx
  128.                 pop     cx
  129.                 pop     ax
  130.  
  131.                 ret                     ; back to caller
  132.  
  133. show_cmd        endp
  134.  
  135. ; --- EDR
  136.  
  137. old_int21    dw    2 dup(?); former int 21h address
  138.  
  139. new_int21    proc    far
  140.         cmp    ah,4bh        ; EXEC function?
  141.         je    exec_beep    ; yes, beep, then call EXEC
  142.         cmp    ah,4dh        ; request to get return code?
  143.         je    retc_beep    ; yes, beep then get return code
  144.         jmp    dp cs:old_int21    ; no, pass it on
  145.  
  146. exec_beep:    call    beep_low    ; beep before EXEC
  147.                 call    show_cmd        ; show the command (EDR)
  148.         jmp    dp cs:old_int21    ; go do EXEC
  149.  
  150. retc_beep:    call    beep_high    ; beep after EXEC
  151.         jmp    dp cs:old_int21    ; go get return code
  152. new_int21    endp
  153.  
  154. start:        mov    ax,3521h    ; get int 21h
  155.         int    21h
  156.         mov    old_int21,bx    ; store offset
  157.         mov    old_int21+2,es    ; store segment
  158.         mov    dx,of new_int21    ; ds:dx -> new int 21h
  159.         mov    ax,2521h
  160.         int    21h
  161.         mov    dx,of start    ; discard excess
  162.         add    dx,0fh
  163.         shr    dx,1
  164.         shr    dx,1
  165.         shr    dx,1
  166.         shr    dx,1
  167.         mov    ax,3100h    ; keep process
  168.         int    21h
  169.  
  170. code        ends
  171.         end    begin
  172. 
  173.